home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / library / __init__.pyc (.txt) next >
Python Compiled Bytecode  |  2014-12-31  |  2KB  |  60 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. '''Various library classes.
  5.  
  6. Libraries are (roughly) dicts of items, and in the case of Quod Libet,
  7. these items are songs. Libraries are in charge of alerting the rest of
  8. the program when songs have been added, changed, or removed. They can
  9. also be queried in various ways.
  10. '''
  11. import time
  12. import threading
  13. from quodlibet import print_d
  14. import quodlibet.formats as formats
  15. from quodlibet.const import LIBRARY_SAVE_PERIOD_SECONDS
  16. from quodlibet.library.libraries import SongFileLibrary, SongLibrary
  17. from quodlibet.library.librarians import SongLibrarian
  18. from quodlibet.util.path import mtime
  19.  
  20. def init(cache_fn = None):
  21.     '''Set up the library and return the main one.
  22.  
  23.     Return a main library, and set a librarian for
  24.     all future SongLibraries.
  25.     '''
  26.     s = ', '.join(formats.modules)
  27.     print_d('Supported formats: %s' % s)
  28.     SongFileLibrary.librarian = SongLibrary.librarian = SongLibrarian()
  29.     library = SongFileLibrary('main')
  30.     if cache_fn:
  31.         library.load(cache_fn)
  32.     return library
  33.  
  34.  
  35. def save(force = False):
  36.     '''Save all registered libraries that have a filename and are marked dirty.
  37.  
  38.     If force = True save all of them blocking, else save non-blocking and
  39.     only if they were last saved more than LIBRARY_SAVE_PERIOD_SECONDS ago.
  40.     '''
  41.     print_d('Saving all libraries...')
  42.     librarian = SongFileLibrary.librarian
  43.     for lib in librarian.libraries.values():
  44.         filename = lib.filename
  45.         if not filename or not (lib.dirty):
  46.             continue
  47.         if force:
  48.             
  49.             try:
  50.                 lib.save()
  51.             except EnvironmentError:
  52.                 pass
  53.  
  54.             lib.destroy()
  55.             continue
  56.         if time.time() - mtime(filename) > LIBRARY_SAVE_PERIOD_SECONDS:
  57.             threading.Thread(target = lib.save).run()
  58.             continue
  59.  
  60.